/*package com.fare.taluo.web.action;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
import org.apache.struts2.ServletActionContext;
import org.foreveross.hbase.client.HBaseHelper;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.crawl.TaskQueueLogApplication;
import com.fare.taluo.application.plane.channel.SourceApplication;
import com.fare.taluo.application.plane.city.PortApplication;
import com.fare.taluo.util.DateJsonValueProcessor;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.util.StringAndDateAndFileUtil;
import com.fare.taluo.vo.core.PortEntityVO;
import com.fare.taluo.vo.core.SourceEntityVO;
import com.fare.taluo.vo.core.StatisticsTotalDetailEntityVO;
import com.fare.taluo.vo.core.StatisticsTotalEntityVO;
import com.fare.taluo.vo.core.TaskRecordEntityVO;
import com.foreveross.taskservice.common.application.ws.IQueryTaskDetailApplicatioin;
import com.foreveross.taskservice.common.bean.TaskModel;

@SuppressWarnings("serial")
@Controller("taskRecordAction")
@Scope("prototype")
public class TaskRecordAction extends BaseFdcAction{
	@Resource(name="taskQueueLogApplication")
	private TaskQueueLogApplication taskRecordApp;
	@Resource(name="sourceApplication")
	private SourceApplication sourceApp;
	@Resource(name="portApplication")
	private PortApplication portApp;
	//加载WEBSERVICSE
		@Resource(name ="iQueryTaskDetailApplicatioinService")
		private IQueryTaskDetailApplicatioin iQueryTaskDetailApplicatioin;
	private List<PortEntityVO> portList;
	private List<SourceEntityVO> sourceList;
	private List<TaskRecordEntityVO> taskRecordList;
	private String fromCity; 	//起始城市
	private String toCity;		//终点城市
	private String grabChannel;	//网站名称
	private String grabChannelID;//网站id
	private Date startTime;		//抓取时间段起始时间
	private Date endTime;		//抓取时间段终止时间
	private String status;		//下载状态
	private String showData;
	private String data;
	private String todayStr=DateUtils.getDateStr("yyyy-MM-dd");
	public void init(){
		portList = portApp.findAllPortEntityVO();
		//CRAWL_STATUS 抓取状态为1的
		sourceList = sourceApp.findAllSourceEntity();
	}

	public String toTaskRecordJSP(){
		init();
		returnPageURL = "/fare/_monitor.jsp";
		return "dispatcher";
	}
	public void toQueryTaskRecordJsp() throws IOException{
		int page=Integer.parseInt(request.getParameter("page"));
	    int pagesize=Integer.parseInt(request.getParameter("pagesize"));
	    String sortorder="";
	    String sortname="";
	    Map map = request.getParameterMap();
	    Set<String> set = map.keySet();
	    String [] sp;
	    for(String key : set){
	    	if(StringUtils.equalsIgnoreCase(key, "sortorder")){
	    		sp = (String[]) map.get(key);
	    		sortorder=sp[0];
	    	}
	    	if(StringUtils.equalsIgnoreCase(key,"sortname")){
	    		sp = (String[]) map.get(key);
	    		sortname=sp[0];
	    	}
	    	System.out.println(map.get("sortorder"));
		    System.out.println(map.get("sortname"));
	    }
	    
	    fromCity=URLDecoder.decode(fromCity, "utf-8");
	    toCity=URLDecoder.decode(toCity, "utf-8");
	    String fromCityCode = null;
		String toCityCode = null;
		//查询出发城市和终点城市的编号
		if (StringAndDateAndFileUtil.checkString(fromCity) && StringAndDateAndFileUtil.checkString(toCity)) {
			//返回航段
			PortEntityVO vo = portApp.findPortEntityByCityName(fromCity);
			if(vo != null){
				fromCityCode = vo.getPortCode();
			}
			PortEntityVO vo2 = portApp.findPortEntityByCityName(toCity);
			if(vo2 != null){
				toCityCode = vo2.getPortCode();
			}
		}
		
		
		List<TaskRecordEntityVO> recordList=getTaskRecordApp().
				findAllTaskRecord(fromCityCode, toCityCode ,grabChannelID, startTime, endTime, status,sortorder,sortname,page,pagesize);
		//符合条件查询的数据的数据
		int totalCount=getTaskRecordApp().getTotalTaskRecordListByCodition(fromCityCode, toCityCode ,grabChannelID, startTime, endTime, status);
		if(recordList!=null){//查找到数据 
				JsonConfig jsonConfig = new JsonConfig();
				jsonConfig.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
				JSONObject tjson = new JSONObject();
				tjson.put("Rows", JSONArray.fromObject(recordList,jsonConfig).toString());
				tjson.put("Total",totalCount);
				showData=tjson.toString();
		}
		 HttpServletResponse response=ServletActionContext.getResponse();
		 response.setContentType("text/html;charset=utf-8"); 
		 response.getWriter().write(showData);
	}
	
	//引擎统计信息，total信息
	public void findTotalDetailInfo() throws Exception{
		String grabdate=request.getParameter("grabdate");
		String grabchannelID=request.getParameter("grabchannelID");
		List<StatisticsTotalEntityVO> recordList =new ArrayList<StatisticsTotalEntityVO>();
		if(todayStr.equals(grabdate)){
			TaskModel[] models=iQueryTaskDetailApplicatioin.query(Long.parseLong(grabchannelID), null,null,null);
			recordList=taskRecordApp.getTotalRecordByWS(models);
		}else{
			recordList=taskRecordApp.getTotalRecordByDateAndChannel(grabdate, grabchannelID);
		}
//		int totalCount=getTaskRecordApp().getCountByDateAndChannel_2(grabdate, grabchannelID);
		int totalCount=recordList.size();
		if(recordList!=null){//查找到数据 
				JsonConfig jsonConfig = new JsonConfig();
				jsonConfig.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
				JSONObject tjson = new JSONObject();
				tjson.put("Rows", JSONArray.fromObject(recordList,jsonConfig).toString());
				tjson.put("Total",totalCount);
				showData=tjson.toString();
		}
		 HttpServletResponse response=ServletActionContext.getResponse();
		 response.setContentType("text/html;charset=utf-8"); 
		 response.getWriter().write(showData);
	}
	//引擎统计信息，success an total详细信息
	public void findTotalAllDetailInfo() throws IOException{
		String grabdate=request.getParameter("grabdate");
		String grabchannelID=request.getParameter("grabchannelID");
		String fromCity=request.getParameter("fromCity");
		String toCity=request.getParameter("toCity");
		List<StatisticsTotalDetailEntityVO> recordList =new ArrayList<StatisticsTotalDetailEntityVO>();
		if(todayStr.equals(grabdate)){
			TaskModel[] models;
			try {
				models = iQueryTaskDetailApplicatioin.query(Long.parseLong(grabchannelID),fromCity,toCity,null);
				recordList=taskRecordApp.getTotalAllByWS(models);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			recordList=taskRecordApp.getTotalAllByDateAndChannel(grabdate, grabchannelID,fromCity,toCity);
		}
		
		
//		int totalCount=getTaskRecordApp().getTotalCountByFromAndTo(time, grabchannelID,fromCity,toCity);
		int totalCount=recordList.size();
		if(recordList!=null){//查找到数据 
				JsonConfig jsonConfig = new JsonConfig();
				jsonConfig.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
				JSONObject tjson = new JSONObject();
				tjson.put("Rows", JSONArray.fromObject(recordList,jsonConfig).toString());
				tjson.put("Total",totalCount);
				showData=tjson.toString();
		}
		 HttpServletResponse response=ServletActionContext.getResponse();
		 response.setContentType("text/html;charset=utf-8"); 
		 response.getWriter().write(showData);
	}
	//引擎统计信息，fail and total失败详细信息
	public void findTotalAndFailDetailInfo() throws IOException{
		String grabdate=request.getParameter("grabdate");
		String grabchannelID=request.getParameter("grabchannelID");
		String fromCity=request.getParameter("fromCity");
		String toCity=request.getParameter("toCity");
		int page=Integer.parseInt(request.getParameter("page"));
	    int pagesize=Integer.parseInt(request.getParameter("pagesize"));
		Date time=DateUtils.strToDate(grabdate,"yyyy-MM-dd");
		List<TaskRecordEntityVO> recordList =new ArrayList<TaskRecordEntityVO>();
		if(todayStr.equals(grabdate)){
			TaskModel[] models;
			try {
				models = iQueryTaskDetailApplicatioin.query(Long.parseLong(grabchannelID),fromCity,toCity,null);
				recordList=taskRecordApp.getTotalAndFailRecordByByWS(models);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			recordList=taskRecordApp.getTotalAndFailRecordByDateAndChannel(time, grabchannelID,fromCity,toCity,page,pagesize);
		}
		
		
		
//		int totalCount=recordList.size();
		int totalCount=getTaskRecordApp().getTotalAndFailCountByDateAndChannel(time, grabchannelID,fromCity,toCity);
		if(recordList!=null){//查找到数据 
				JsonConfig jsonConfig = new JsonConfig();
				jsonConfig.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
				JSONObject tjson = new JSONObject();
				tjson.put("Rows", JSONArray.fromObject(recordList,jsonConfig).toString());
				tjson.put("Total",totalCount);
				showData=tjson.toString();
		}
		 HttpServletResponse response=ServletActionContext.getResponse();
		 response.setContentType("text/html;charset=utf-8"); 
		 response.getWriter().write(showData);
	}
	
	
	//引擎统计信息，total失败详细信息
	public void findTotalFailDetailInfo() throws IOException{
		String grabdate=request.getParameter("grabdate");
		String grabchannelID=request.getParameter("grabchannelID");
		String status=request.getParameter("status");
		String fromCity=request.getParameter("fromCity");
		String toCity=request.getParameter("toCity");
		int page=Integer.parseInt(request.getParameter("page"));
	    int pagesize=Integer.parseInt(request.getParameter("pagesize"));
		Date time=DateUtils.strToDate(grabdate,"yyyy-MM-dd");
		List<TaskRecordEntityVO> recordList=taskRecordApp.getTotalRecordByDateAndChannel(time, grabchannelID,status,fromCity,toCity,page,pagesize);
		int totalCount=getTaskRecordApp().getTotalCountByDateAndChannel(time, grabchannelID,status,fromCity,toCity);
//		int totalCount=recordList.size();
		if(recordList!=null){//查找到数据 
				JsonConfig jsonConfig = new JsonConfig();
				jsonConfig.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
				JSONObject tjson = new JSONObject();
				tjson.put("Rows", JSONArray.fromObject(recordList,jsonConfig).toString());
				tjson.put("Total",totalCount);
				showData=tjson.toString();
		}
		 HttpServletResponse response=ServletActionContext.getResponse();
		 response.setContentType("text/html;charset=utf-8"); 
		 response.getWriter().write(showData);
	}
	//引擎统计信息，失败详细信息
	public void findFailDetailInfo() throws IOException{
		String grabdate=request.getParameter("grabdate");
		String grabchannelID=request.getParameter("grabchannelID");
		String status=request.getParameter("status");
		int page=Integer.parseInt(request.getParameter("page"));
	    int pagesize=Integer.parseInt(request.getParameter("pagesize"));
		Date time=DateUtils.strToDate(grabdate,"yyyy-MM-dd");
		List<TaskRecordEntityVO> recordList=taskRecordApp.getTaskRecordByDateAndChannel(time, grabchannelID,status,page,pagesize);
		int totalCount=getTaskRecordApp().getCountByDateAndChannel(time, grabchannelID,status);
//		int totalCount=recordList.size();
		if(recordList!=null){//查找到数据 
				JsonConfig jsonConfig = new JsonConfig();
				jsonConfig.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
				JSONObject tjson = new JSONObject();
				tjson.put("Rows", JSONArray.fromObject(recordList,jsonConfig).toString());
				tjson.put("Total",totalCount);
				showData=tjson.toString();
		}
		 HttpServletResponse response=ServletActionContext.getResponse();
		 response.setContentType("text/html;charset=utf-8"); 
		 response.getWriter().write(showData);
	}
	
	
	//HBase 返回抓取到的页面内容  (CRAWL_PF_SOURCE_DATA HBase数据库)
	public void fetchContent() throws IOException{
		String sourceRowKey=request.getParameter("sourceRowKey");
		Result result = HBaseHelper.getOneRecord("CRAWL_PF_SOURCE_DATA",sourceRowKey);
		String data=null;
		for (KeyValue kv : result.raw()) {
			if(new String(kv.getQualifier()).equalsIgnoreCase("CONTENTS")){
				data=new String(kv.getValue(),"UTF-8");
			}
		}
		HttpServletResponse response=ServletActionContext.getResponse();
		 response.setContentType("text/html;charset=utf-8"); 
		 response.getWriter().write(data);
	}
	
	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public TaskQueueLogApplication getTaskRecordApp() {
		return taskRecordApp;
	}

	public void setTaskRecordApp(TaskQueueLogApplication taskRecordApp) {
		this.taskRecordApp = taskRecordApp;
	}

	public SourceApplication getSourceApp() {
		return sourceApp;
	}

	public void setSourceApp(SourceApplication sourceApp) {
		this.sourceApp = sourceApp;
	}

	public PortApplication getPortApp() {
		return portApp;
	}

	public void setPortApp(PortApplication portApp) {
		this.portApp = portApp;
	}

	public List<PortEntityVO> getPortList() {
		return portList;
	}

	public void setPortList(List<PortEntityVO> portList) {
		this.portList = portList;
	}

	public List<SourceEntityVO> getSourceList() {
		return sourceList;
	}

	public void setSourceList(List<SourceEntityVO> sourceList) {
		this.sourceList = sourceList;
	}

	public List<TaskRecordEntityVO> getTaskRecordList() {
		return taskRecordList;
	}

	public void setTaskRecordList(List<TaskRecordEntityVO> taskRecordList) {
		this.taskRecordList = taskRecordList;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getGrabChannel() {
		return grabChannel;
	}

	public void setGrabChannel(String grabChannel) {
		this.grabChannel = grabChannel;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getShowData() {
		return showData;
	}

	public void setShowData(String showData) {
		this.showData = showData;
	}

	public String getGrabChannelID() {
		return grabChannelID;
	}

	public void setGrabChannelID(String grabChannelID) {
		this.grabChannelID = grabChannelID;
	}

}
*/